<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;
class UserRequest extends FormRequest
{
    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    public function rules()
    {
        $user = $this->user;
        $passwordRule = $user ? '': 'required|min:6|max:20|confirmed';
        return [
            'email' => ['required', 'email', Rule::unique('users')->ignore($user)],
            'name' => ['required','min:3','max:20',Rule::unique('users')->ignore($user)],
            'password' => $passwordRule,
        ];
    }
}
